﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace GUI
{
    public partial class formNhapSoLuongPin : Form
    {
        public formNhapSoLuongPin()
        {
            InitializeComponent();
        }

        private int slPin;
        public int SlPin
        {
            set { slPin = value; }
            get { return slPin; }
        }
        private void formNhapSoLuongPin_Load(object sender, EventArgs e)
        {
            for (int i = 1; i < 1000; i++)
            {
                dmSL.Items.Add(i);
            }
            dmSL.Text = slPin.ToString();
        }

        private void dmSL_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                slPin = int.Parse(dmSL.Text);
                Close();
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            slPin = int.Parse(dmSL.Text);
            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            slPin = -1;
            Close();
        }
        void a_KeyPress(object sender, KeyPressEventArgs e)
        {
            string decimalString = Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyDecimalSeparator;
            char decimalChar = Convert.ToChar(decimalString);
            DomainUpDown a = sender as DomainUpDown;
            if (Char.IsDigit(e.KeyChar) || Char.IsControl(e.KeyChar)) { }
            else if (e.KeyChar == decimalChar && a.Text.IndexOf(decimalString) == -2)
            { }
            else
            {
                e.Handled = true;
            }
        }
    }
}
